package com.cunshe.service;

import com.cunshe.dao.ProductFeatureDao;
import com.cunshe.domain.ProductFeature;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ProductFeatureService {

    @Autowired
    private ProductFeatureDao productFeatureDao;

    @Transactional(rollbackFor = Exception.class)
    public int insert(ProductFeature record) {
        record.setStatus(true);
        return productFeatureDao.insert(record);
    }

    @Transactional(rollbackFor = Exception.class)
    public int delete(Long id) {
        return productFeatureDao.delete(id);
    }

    @Transactional(rollbackFor = Exception.class)
    public int update(ProductFeature record) {
        return productFeatureDao.update(record);
    }

    public List<ProductFeature> getByMenuId(Long menuId, boolean status) {
        return list(ProductFeature.builder().menuId(menuId).status(status).build());
    }

    public List<ProductFeature> list(ProductFeature record) {
        PageHelper.orderBy(" order_num DESC, id DESC ");
        return productFeatureDao.list(record);
    }

}